package com.bjbn.controller;

import com.bjbn.model.dto.CommonRequest;
import com.bjbn.model.dto.CommonResponse;
import com.bjbn.service.ParkingDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 停车场数据控制器
 */
@RestController
@Slf4j
@Tag(name = "停车场数据接口", description = "停车场相关数据的新增接口")
public class ParkingDataController {

    @Autowired
    private ParkingDataService parkingDataService;

    /**
     * 保存室外停车场数据
     */
    @PostMapping("/parkSpace")
    @Operation(summary = "保存室外停车场数据", description = "用于保存室外停车场信息数据")
    public CommonResponse saveOutdoorParkingData(
            @Parameter(description = "请求参数，包含数据项和签名信息",
                    schema = @Schema(example = "{\"ts\":\"20171124125469456\",\"sn\":\"14B50BBC30E9471C8F8AC4ADA0D8DA51\",\"ve\":\"1.0\",\"data_items\":\"[{\\\"item_id\\\":\\\"435FA12F3C4747B0BA48E945868FC420\\\",\\\"park_name\\\":\\\"室外测试车场\\\",\\\"park_code\\\":\\\"test_outdoor\\\",\\\"total_space\\\":500,\\\"remain_space\\\":300,\\\"in_space\\\":200,\\\"booking_space\\\":0,\\\"space_rate\\\":\\\"0.40\\\"}]\"}"))
            @RequestBody CommonRequest request) {
        log.debug("接收室外停车场数据请求: {}", request);
        return parkingDataService.saveOutdoorParkingData(request);
    }

    /**
     * 保存室内停车场数据
     */
    @PostMapping("/cwgj/parkSpace")
    @Operation(summary = "保存室内停车场数据", description = "用于保存室内停车场信息数据")
    public CommonResponse saveIndoorParkingData(
            @Parameter(description = "请求参数，包含数据项和签名信息",
                    schema = @Schema(example = "{\"ts\":\"20171124125469456\",\"sn\":\"45949B5B1EDF3D817F09DD2E39F638FE\",\"ve\":\"1.0\",\"data_items\":\"[{\\\"item_id\\\":\\\"435FA12F3C4747B0BA48E945868FC420\\\",\\\"park_name\\\":\\\"室内测试车场\\\",\\\"park_code\\\":\\\"test_outdoor\\\",\\\"total_space\\\":500,\\\"remain_space\\\":300,\\\"in_space\\\":200,\\\"booking_space\\\":0,\\\"space_rate\\\":\\\"0.40\\\"}]\"}"))
            @RequestBody CommonRequest request) {
        log.debug("接收室内停车场数据请求: {}", request);
        return parkingDataService.saveIndoorParkingData(request);
    }

    /**
     * 保存车位状态数据
     */
    @PostMapping("/place/status")
    @Operation(summary = "保存车位状态数据", description = "用于保存车位状态信息数据")
    public CommonResponse saveParkingSpaceStatusData(
            @Parameter(description = "请求参数，包含数据项和签名信息",
                    schema = @Schema(example = "{\"ts\":\"20171124125469456\",\"sn\":\"14B50BBC30E9471C8F8AC4ADA0D8DA51\",\"ve\":\"1.0\",\"data_items\":\"[{\'item_id\':\'PS001\',\'code\':\'A001\',\'area\':\'A区\',\'park_name\':\'测试车场\',\'park_code\':\'test\',\'floor\':\'1F\',\'book_flag\':\'1\',\'car_no\':\'京A12345\',\'reco_time\':\'2023-06-01 10:00:00\',\'place_type\':\'0\',\'place_status\':\'0\',\'berth_type\':\'1\',\'status\':\'NORMAL\',\'park_id\':\'PARK001\'}]\"}"))
            @RequestBody CommonRequest request) {
        log.debug("接收车位状态数据请求: {}", request);
        return parkingDataService.saveParkingSpaceStatusData(request);
    }

    /**
     * 保存入场信息数据
     */
    @PostMapping("/parkIn")
    @Operation(summary = "保存入场信息数据", description = "用于保存车辆入场信息数据")
    public CommonResponse saveEntryInfoData(
            @Parameter(description = "请求参数，包含数据项和签名信息",
                    schema = @Schema(example = "{\"ts\":\"20171124125469456\",\"sn\":\"14B50BBC30E9471C8F8AC4ADA0D8DA51\",\"ve\":\"1.0\",\"data_items\":\"[{\'item_id\':\'IN001\',\'park_name\':\'测试车场\',\'park_code\':\'test\',\'in_time\':\'2023-06-0110:00:00\',\'in_operator\':\'admin\',\'car_number\':\'京A12345\',\'equip_name\':\'入口设备1\',\'equip_id\':\'EQ001\',\'equip_code\':\'EC001\',\'vehicle_info\':\'{color:red, type:car}\',\'event_type\':\'ENTRY\'}]\"}"))
            @RequestBody CommonRequest request) {
        log.debug("接收入场信息数据请求: {}", request);
        return parkingDataService.saveEntryInfoData(request);
    }

    /**
     * 保存出场信息数据
     */
    @PostMapping("/parkOut")
    @Operation(summary = "保存出场信息数据", description = "用于保存车辆出场信息数据")
    public CommonResponse saveExitInfoData(
            @Parameter(description = "请求参数，包含数据项和签名信息",
                    schema = @Schema(example = "{\"ts\":\"20171124125469456\",\"sn\":\"14B50BBC30E9471C8F8AC4ADA0D8DA51\",\"ve\":\"1.0\",\"data_items\":\"[{\'item_id\':\'OUT001\',\'park_name\':\'测试车场\',\'park_code\':\'test\',\'car_number\':\'京A12345\',\'out_time\':\'2023-06-0112:00:00\',\'in_time\':\'2023-06-0110:00:00\',\'in_equip_id\':\'EQ001\',\'in_equip_code\':\'EC001\',\'in_equip_name\':\'入口设备1\',\'in_record_id\':\'IN001\',\'event_type\':\'EXIT\',\'out_operator\':\'admin\',\'out_equip_id\':\'EQ002\',\'out_equip_code\':\'EC002\',\'out_equip_name\':\'出口设备1\',\'vehicle_info\':\'{color:red, type:car}\'}]\"}"))
            @RequestBody CommonRequest request) {
        log.debug("接收出场信息数据请求: {}", request);
        return parkingDataService.saveExitInfoData(request);
    }

    /**
     * 保存收费记录数据
     */
    @PostMapping("/park/parkCharge")
    @Operation(summary = "保存收费记录数据", description = "用于保存收费记录信息数据")
    public CommonResponse saveChargeRecordData(
            @Parameter(description = "请求参数，包含数据项和签名信息",
                    schema = @Schema(example = "{\"ts\":\"20171124125469456\",\"sn\":\"14B50BBC30E9471C8F8AC4ADA0D8DA51\",\"ve\":\"1.0\",\"data_items\":\"[{\'item_id\':\'CHARGE001\',\'park_name\':\'测试车场\',\'park_code\':\'test\',\'car_number\':\'京A12345\',\'fees_time\':\'2023-06-01 12:00:00\',\'ys_money\':10.00,\'yh_money\':0.00,\'ss_money\':10.00,\'net_discount_money\':0.00,\'hg_money\':0.00,\'in_time\':\'2023-06-01 10:00:00\',\'operator_id\':\'OP001\',\'operator_name\':\'admin\',\'equipment_id\':\'EQ002\',\'park_in_id\':\'IN001\',\'pay_type\':\'微信支付\',\'pay_from\':\'jieshun\',\'dk_flag\':\'0\'}]\"}"))
            @RequestBody CommonRequest request) {
        log.debug("接收收费记录数据请求: {}", request);
        return parkingDataService.saveChargeRecordData(request);
    }
}